<template>
  <div class="app-container">
    <!-- 添加或修改入伙登记对话框 -->
      <el-form ref="form" :model="form" :rules="rules" label-width="80px" class="form-flex">
        <fieldset>
          <legend>入伙信息</legend>
          <el-row :gutter="20">
            <el-col :span="8" :xs="24">
              <el-form-item label="入伙时间" prop="joinTime">
                <el-date-picker clearable size="small" :disabled="disabled"
                                v-model="form.joinTime"
                                type="date"
                                value-format="yyyy-MM-dd"
                                placeholder="选择入伙时间">
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="8" :xs="24">
              <el-form-item label="购房合同" prop="houseContractNum">
                <el-input v-model="form.houseContractNum" placeholder="请输入购房合同号" :disabled="disabled"/>
              </el-form-item>
            </el-col>
            <el-col :span="8" :xs="24">
              <el-form-item label="收楼书号" prop="bookNum">
                <el-input v-model="form.bookNum" placeholder="请输入收楼书号" :disabled="disabled"/>
              </el-form-item>
            </el-col>
            <el-col :span="8" :xs="24">
              <el-form-item label="通知书" prop="joinNotice">
                <el-input v-model="form.joinNotice" placeholder="请输入通知书" :disabled="disabled"/>
              </el-form-item>
            </el-col>
            <el-col :span="8" :xs="24">
              <el-form-item label="产权证号" prop="propertyRightNumber">
                <el-input v-model="form.propertyRightNumber" placeholder="请输入产权证号" :disabled="disabled"/>
              </el-form-item>
            </el-col>
            <el-col :span="8" :xs="24">
              <el-form-item label="土地证号" prop="landNumber">
                <el-input v-model="form.landNumber" placeholder="请输入土地证号" :disabled="disabled"/>
              </el-form-item>
            </el-col>
            <el-col :span="24" :xs="24">
              <el-form-item label="认证材料" prop="depositPosition" >
                <el-input
                  type="textarea"
                  :rows="4"
                  placeholder="请输入内容"
                  v-model="form.depositPosition"
                  :disabled="disabled"
                />
              </el-form-item>
            </el-col>
          </el-row>
        </fieldset>
        <fieldset>
          <legend>档案信息</legend>
          <join-file-list ref="fileListRef" :joinRegisterId="form.id" :disabled="disabled"/>
        </fieldset>
      </el-form>
  </div>
</template>

<script>
  import {selectJoinByRoomId } from "@/api/waitress/joinRegister";
  import CustomFilterable from "@/views/components/filterable/CustomFilterable"
  import { listCustomInfo } from "@/api/waitress/customInfo";
  import { getRoom } from "@/api/property/room";
  import { roomMixin } from "@/views/property/houseMange/roomMixin.js"
  import JoinFileList from "../../../waitress/joinRegister/joinFileList";
  export default {
    name: "JoinRegisterFrom",
    dicts: ['custom_type', 'sys_user_sex'],
    mixins:[ roomMixin ],
    components:{CustomFilterable,JoinFileList},
    props: {
      currentNode: {
        type: Object,
        default: () => {
        }
      },
    },
    data() {
      return {
        activeNames:['zichan','yezhu','ruhuo','dangan'],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        //是否禁用
        disabled: true,
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          customName: [
            {required: true, message: "业主名称不能为空", trigger: "blur"}
          ],
          roomId: [
            {required: true, message: "房产信息不能为空", trigger: "blur"}
          ],
          joinTime: [
            {required: true, message: "入伙时间不能为空", trigger: "blur"}
          ],
          cellPhoneNumber: [
            {
              pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
              message: "请输入正确的手机号码",
              trigger: "blur"
            }
          ],
          idCard: [
            {required: false, validator: this.checkIDCard, trigger: 'blur'}
          ]
        },
        roomForm:{}
      };
    },
    watch: {
      currentNode(v) {
        this.initForm()
      }
    },
    created() {
      this.initForm()
    },
    methods: {
      initForm() {
        this.reset();
        if (this.currentNode.modelType == 'room') {
          getRoom(this.currentNode.id).then(response => {
            this.roomForm = response.data;
            selectJoinByRoomId({'roomId':this.roomForm.id,'customId':this.roomForm.ownerId}).then(response => {
              this.form = response.data;
              this.getBuildingData(this.form.communityId)
              this.getUnitList(this.form.floorId)
              this.getRoomListData(this.form.unitId)
            });
          });

        }
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
        this.$emit("cancel")
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          communityId: null,
          floorId: null,
          roomId: null,
          unitId:null,
          ownerId: null,
          joinTime: null,
          houseContractNum: null,
          bookNum: null,
          joinNotice: null,
          depositPosition: null,
          propertyRightNumber: null,
          landNumber: null,
          //业主信息
          customId: null, //业主Id
          customType: '001', //业主类型
          sex: '2', //业主性别
          customName: null, //客户姓名
          customHeadImg: null, //客户头像
          cellPhoneNumber: null, //手机号码
          idCard: null, //身份证号
          birthDate: null, //出生日期
          corporateName: null, //公司名称
          contactAddress: null, //联系地址
          linkman: null, //联系人
          joinFileList:[]
        };
        this.resetForm("form");
      },
      changeCustomName(v){
        listCustomInfo({customName : v,customType : this.customType}).then(res=>{
          if(res.rows.length > 0){
            this.form = Object.assign(this.form,{
              customId:res.rows[0].customId,
              customName:res.rows[0].customName,
              customHeadImg:res.rows[0].customHeadImg,
              cellPhoneNumber:res.rows[0].cellPhoneNumber,
              idCard:res.rows[0].idCard,
              birthDate:res.rows[0].birthDate,
              corporateName:res.rows[0].corporateName,
              contactAddress:res.rows[0].contactAddress,
              linkman:res.rows[0].linkman,
            })
          }else{
            this.form = Object.assign(this.form,{
              customId: null,
              customHeadImg: null,
              customName: v,
              cellPhoneNumber: null,
              idCard: null,
              birthDate: null,
              corporateName: null,
              contactAddress: null,
              linkman: null,
            })
          }
        })
      },
    }
  };
</script>

<style scoped>

</style>
